package net.hserver.admin.system.utils;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

/**
 * 加密工具
 */
public class RsaUtil {
    private static final String pbk = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmqmQ2/Emso52xNcbzO/WDv/bFG/u1w+NrDJSCiUZDGHKyijXcG3BDpuWOTS5yuE79pfDHsBbNr/QPKKBk3/PmY/mqXsAf/fU17/TFG6hFlP0scf3ucphvFmqBYio4ZeLOtiLi2GSeGgk82g3mbKq+UWvDFeULOK4wIYm4e8OwnwIDAQAB";
    private static final String prk = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKaqZDb8SayjnbE1xvM79YO/9sUb+7XD42sMlIKJRkMYcrKKNdwbcEOm5Y5NLnK4Tv2l8MewFs2v9A8ooGTf8+Zj+apewB/99TXv9MUbqEWU/Sxx/e5ymG8WaoFiKjhl4s62IuLYZJ4aCTzaDeZsqr5Ra8MV5Qs4rjAhibh7w7CfAgMBAAECgYAGKjMBxlbn+rdds4pekJRgzAwnN1qaBcXBkxoNMrcKyqU3eHL3PNFBbLN8uNsj0DB6eRW3yooqupGcW+7ZkbUg/Gh157xwGpiNjygvv4TEpA6/LGNUt4/I1Tte6JbHPqFTD4IDTWCDIesCtiVicBYxkJ4kY7K7Tsnll2honaN5RQJBANW/Z17FTPWaV6aLOb1z1nTkHoHk2D2kBBdY7ulpgmDRzE/zGdUVReALZ2mHTCep96Ru1wqT7/hJRluCqC0TSd0CQQDHnGwPD/rA5dNsM0G5JShWNr1iLy6TzdBAJs0adulwz0lP2AOC3PUpD/LZ4+Btqf1GY93thh5h3c5xYvQkOiKrAkB+rDMfl//W4cQmIAZ0/0xN888cnbmFNklyaLMVwwCQTmUt0F0zyaqibz+264a3TuRDH6jzTN7/HrXCj7kJFZBFAkBTcrtiGKYV2n7mrw783eHdGQlXcK4iMFqtVwtL0waImL/nV0EwhjsfrYEzQibi8bvmn315/SXaeCYEFQBH3N39AkAYW3ewSNdfIDpEmNZAh+uTj1NXV+cmLSt/zhDLLxzGTGRtnLqxYg6AQdPBs5mhV/bVWXfsJ42YYBtuY1UN//Fh";
    private static final RSA rsa = new RSA(prk, pbk);

    public static String encrypt(String s) {
        return rsa.encryptBase64(s, KeyType.PublicKey);
    }

    public static String decrypt(String s) {
        return rsa.decryptStr(s, KeyType.PrivateKey);
    }


    public static void main(String[] args) {
//        RSA rsa = new RSA();
//
//        //获得私钥
//        String privateKeyBase64 = rsa.getPrivateKeyBase64();
//        //获得公钥
//        String publicKeyBase64 = rsa.getPublicKeyBase64();
//
//        //公钥加密，私钥解密
//        String encrypt = rsa.encryptBase64("Zhj@%364210516", KeyType.PublicKey);
//        String decrypt = rsa.decryptStr(encrypt, KeyType.PrivateKey);

        String encrypt = RsaUtil.encrypt("123456");
        String decrypt = RsaUtil.decrypt(encrypt);
    }
}
